package com.edu.exam.entity.examination.paper;

import com.edu.exam.enums.exam.ExamType;
import com.edu.exam.enums.ArrangementStatus;
import com.edu.exam.enums.ExamForm;
import com.edu.exam.enums.ConfirmationStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 自动安排结果实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：auto_arrangement_result
 *
 * <p>自动安排结果实体，存储自动安排任务的结果信息。
 * 每个结果对应一个考试的考场安排详情，包含考场、座位、
 * 时间安排等完整信息，支持结果追踪和管理。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AutoArrangementResult {

    /**
     * 结果ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long resultId;

    /**
     * 任务ID
     */
    @Column(name = "task_id", nullable = false)
    private Long taskId;

    /**
     * 考试ID
     */
    @Column(name = "exam_id", nullable = false)
    private Long examId;

    /**
     * 考试编码
     */
    @Column(name = "exam_code", length = 50, nullable = false)
    private String examCode;

    /**
     * 考试名称
     */
    @Column(name = "exam_name", length = 200, nullable = false)
    private String examName;

    /**
     * 考场ID
     */
    @Column(name = "venue_id", nullable = false)
    private Long venueId;

    /**
     * 考场编码
     */
    @Column(name = "venue_code", length = 50, nullable = false)
    private String venueCode;

    /**
     * 考场名称
     */
    @Column(name = "venue_name", length = 200, nullable = false)
    private String venueName;

    /**
     * 考场位置
     */
    @Column(name = "venue_location", length = 300)
    private String venueLocation;

    /**
     * 考场容量
     */
    @Column(name = "venue_capacity")
    private Integer venueCapacity;

    /**
     * 安排状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "arrangement_status", length = 20, nullable = false)
    private ArrangementStatus arrangementStatus;

    /**
     * 安排时间
     */
    @Column(name = "arrangement_time")
    private LocalDateTime arrangementTime;

    /**
     * 考试日期
     */
    @Column(name = "exam_date", nullable = false)
    private LocalDateTime examDate;

    /**
     * 开始时间
     */
    @Column(name = "start_time", nullable = false)
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    @Column(name = "end_time", nullable = false)
    private LocalDateTime endTime;

    /**
     * 考试时长（分钟）
     */
    @Column(name = "exam_duration")
    private Integer examDuration;

    /**
     * 应考人数
     */
    @Column(name = "total_students")
    private Integer totalStudents;

    /**
     * 实考人数
     */
    @Column(name = "actual_students")
    private Integer actualStudents;

    /**
     * 安排座位数
     */
    @Column(name = "allocated_seats")
    private Integer allocatedSeats;

    /**
     * 座位起始编号
     */
    @Column(name = "seat_start_number")
    private String seatStartNumber;

    /**
     * 座位结束编号
     */
    @Column(name = "seat_end_number")
    private String seatEndNumber;

    /**
     * 监考教师1 ID
     */
    @Column(name = "invigilator1_id")
    private Long invigilator1Id;

    /**
     * 监考教师1姓名
     */
    @Column(name = "invigilator1_name", length = 100)
    private String invigilator1Name;

    /**
     * 监考教师2 ID
     */
    @Column(name = "invigilator2_id")
    private Long invigilator2Id;

    /**
     * 监考教师2姓名
     */
    @Column(name = "invigilator2_name", length = 100)
    private String invigilator2Name;

    /**
     * 考试形式
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "exam_form", length = 20)
    private ExamForm examForm;

    /**
     * 考试类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "exam_type", length = 20)
    private ExamType examType;

    /**
     * 是否需要特殊设备
     */
    @Column(name = "requires_special_equipment")
    private Boolean requiresSpecialEquipment;

    /**
     * 特殊设备说明
     */
    @Column(name = "special_equipment_note", length = 500)
    private String specialEquipmentNote;

    /**
     * 是否无障碍考场
     */
    @Column(name = "is_accessible_venue")
    private Boolean isAccessibleVenue;

    /**
     * 冲突检测结果
     */
    @Column(name = "conflict_check_result", columnDefinition = "TEXT")
    private String conflictCheckResult;

    /**
     * 冲突数量
     */
    @Column(name = "conflict_count")
    private Integer conflictCount;

    /**
     * 安排质量分数
     */
    @Column(name = "quality_score")
    private Double qualityScore;

    /**
     * 优化目标达成度
     */
    @Column(name = "optimization_achievement", columnDefinition = "TEXT")
    private String optimizationAchievement;

    /**
     * 安排备注
     */
    @Column(name = "arrangement_note", length = 1000)
    private String arrangementNote;

    /**
     * 是否推荐安排
     */
    @Column(name = "is_recommended")
    private Boolean isRecommended;

    /**
     * 推荐理由
     */
    @Column(name = "recommendation_reason", length = 500)
    private String recommendationReason;

    /**
     * 人工调整标记
     */
    @Column(name = "manual_adjustment")
    private Boolean manualAdjustment;

    /**
     * 调整人ID
     */
    @Column(name = "adjusted_by")
    private Long adjustedBy;

    /**
     * 调整人姓名
     */
    @Column(name = "adjusted_by_name", length = 100)
    private String adjustedByName;

    /**
     * 调整时间
     */
    @Column(name = "adjustment_time")
    private LocalDateTime adjustmentTime;

    /**
     * 调整原因
     */
    @Column(name = "adjustment_reason", length = 500)
    private String adjustmentReason;

    /**
     * 确认状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "confirmation_status", length = 20)
    private ConfirmationStatus confirmationStatus;

    /**
     * 确认人ID
     */
    @Column(name = "confirmed_by")
    private Long confirmedBy;

    /**
     * 确认人姓名
     */
    @Column(name = "confirmed_by_name", length = 100)
    private String confirmedByName;

    /**
     * 确认时间
     */
    @Column(name = "confirmation_time")
    private LocalDateTime confirmationTime;

    /**
     * 确认备注
     */
    @Column(name = "confirmation_note", length = 500)
    private String confirmationNote;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 任务关联
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "task_id", insertable = false, updatable = false)
    private AutoArrangementTask task;
}